package Validator

import (
	"github.com/go-playground/validator/v10"
	"wskyygyso/casually/AppInit"
)

type CommentTernsBannedShow struct {
	Id int `binding:"required,gt=0,IdExists"`
}

type CommentTernsBannedStore struct {
	AdvertiserIds []string `form:"advertiser_ids" json:"advertiser_ids" binding:"required"`
	Terms         []string `form:"terms" json:"terms"  binding:"required"`
}

func IdExists(f1 validator.FieldLevel) bool {
	if id, ok := f1.Field().Interface().(int); ok {
		var count int
		AppInit.GetDb().Table("tt_comment_banned_terms").Where("id=?", id).Count(&count)
		return count > 0
	}
	return false
}
